package cn.concurrence;

import java.util.ArrayList;
import java.util.List;

/**
 * @author summit
 * @since 2022/4/19 17:10
 */
public class SynchroTest2 extends SynchroTest1 {

}


class SyncTestMain {

	public static void main(String[] args) throws InterruptedException {
//		SynchroTest1 s1 = new SynchroTest1();
//
//		List<Thread> list = new ArrayList<>();
//		for (int i = 0; i < 10; i++) {
//			Thread thread = new Thread(() -> {
//				for (int j = 0; j < 10; j++) {
//					s1.addOne();
//				}
//			});
//			thread.start();
//			list.add(thread);
//		}
//
//		for (Thread thread : list) {
//			thread.join();
//		}
//
//		System.out.println("s1当前值为" + s1.getA());

		List<Thread> list2 = new ArrayList<>();

		SynchroTest2 s2 = new SynchroTest2();
		for (int i = 0; i < 10; i++) {
			Thread thread = new Thread(() -> {
				for (int j = 0; j < 10; j++) {
					s2.addOne();
				}
			});
			list2.add(thread);
			thread.start();
		}
		for (Thread thread : list2) {
			thread.join();
		}
		System.out.println("s2当前值为" + s2.getA());

	}
}